package util;

import java.io.InputStream;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import POJO.User;

public class MybatisSession {

   static SqlSessionFactory sessionfactory;
	public static SqlSessionFactory getFactory() {
		String resource = "mybatis_config.xml";
		InputStream is = MybatisSession.class.getClassLoader().getResourceAsStream(resource);
		sessionfactory = new SqlSessionFactoryBuilder().build(is);
		return sessionfactory;
	}
	
	public static SqlSession openSession() {
		
		return MybatisSession.getFactory().openSession();
		
	}
	
	
	public static void main(String[] args) {
		SqlSession session = MybatisSession.getFactory().openSession();
		
		String statement = "mapper.userMapper.getUserByNamePassword";
		User user = new User();
		user.setName("aaa");
		user.setPassword("123");
		User u = session.selectOne(statement,user);
		System.out.println(u);
	}
}
